package vm;

import javafx.beans.property.SimpleStringProperty;
import os.*;

/**
 * Registras
 * @author Paulius Dambrauskas
 */
public class Register {

    public SimpleStringProperty registerName;
    public SimpleStringProperty registerValue;
    public int registerSize = 4;     
    public Register(String name, int value){
        this.registerName = new SimpleStringProperty(name);
        this.registerValue = new SimpleStringProperty(value+"");
       
    }
    public Register(String name, int value, int size){
        this.registerName = new SimpleStringProperty(name);
        this.registerValue = new SimpleStringProperty(value+"");
        this.registerSize = size;
       
    }
    public Register(String name, String value, int size){
        this.registerName = new SimpleStringProperty(name);
        this.registerValue = new SimpleStringProperty(value);
        this.registerSize = size;
       
    }
    public SimpleStringProperty registerNameProperty(){
        return registerName;
    }
    public SimpleStringProperty registerValueProperty(){
        return registerValue;
    }
    public void setRegisterValue(String value){
        try{
         OS.processes.get(OS.currentProcess).regs.put(registerName.get(), value);
        } catch (Exception e){}
        if(value.length() <= this.registerSize*16)
            this.registerValue.set(value);
        else
           System.out.println("Bloga įvestis");
        
    }
   
    public int getIntVal(){
        return Integer.parseInt(this.registerValue.getValue());
    }
}
